package com.zqj.project.converter;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zqj.project.dto.OrderDetailDTO;
import com.zqj.project.entity.OrderDetailPO;
import com.zqj.project.model.OrderDetail;
import com.zqj.project.vo.OrderDetailVO;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description: OrderConverter
 * @Author: 22001010704 Zhang Qijian
 * @CreateTime: 2024/12/8 20:53
 * @Version: 1.0
 */
public class OrderDetailConverter {

    private OrderDetailConverter() {
        throw new IllegalStateException("Utility Class");
    }

    public static OrderDetailVO toOrderDetailVo(OrderDetail orderDetail) {
        return BeanUtil.toBean(orderDetail, OrderDetailVO.class);
    }

    public static OrderDetail toOrderDetailModel(OrderDetailDTO orderDetailDto) {
        return BeanUtil.toBean(orderDetailDto, OrderDetail.class);
    }

    public static OrderDetail toOrderDetailModel(OrderDetailPO orderDetailPo) {
        return BeanUtil.toBean(orderDetailPo, OrderDetail.class);
    }

    public static OrderDetailPO toOrderDetailPo(OrderDetail orderDetail) {
        return BeanUtil.toBean(orderDetail, OrderDetailPO.class);
    }

    public static List<OrderDetailVO> toOrderDetailVoList(List<OrderDetail> orderDetailModelList) {
        if (CollUtil.isEmpty(orderDetailModelList)) {
            return Collections.emptyList();
        }
        return orderDetailModelList.stream().map(e -> BeanUtil.toBean(e, OrderDetailVO.class)).toList();
    }

    public static List<OrderDetail> toOrderDetailModelList(List<OrderDetailPO> orderDetailPoList) {
        if (CollUtil.isEmpty(orderDetailPoList)) {
            return Collections.emptyList();
        }
        return orderDetailPoList.stream().map(e -> BeanUtil.toBean(e, OrderDetail.class)).toList();
    }

    public static IPage<OrderDetailVO> toOrderDetailVoPage(IPage<OrderDetail> orderDetailModelPage) {
        IPage<OrderDetailVO> orderDetailVoPage = new Page<>(orderDetailModelPage.getCurrent(), orderDetailModelPage.getSize());
        List<OrderDetailVO> orderDetailVoList = new ArrayList<>();
        if (CollUtil.isNotEmpty(orderDetailModelPage.getRecords())) {
            orderDetailModelPage.getRecords().forEach(entity -> orderDetailVoList.add(BeanUtil.toBean(entity, OrderDetailVO.class)));
            orderDetailVoPage.setRecords(orderDetailVoList);
            orderDetailVoPage.setTotal(orderDetailModelPage.getTotal());
        }
        return orderDetailVoPage;
    }

}